local skill = fk.CreateSkill {
  name = "lucky_coin_skill",
}

skill:addEffect("cardskill", {
  prompt = "#lucky_coin_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.CanUseToSelf,
  on_effect = function(self, room, effect)
    local to = effect.to
    if not to or to.dead then return end
    local judge = {
      who = to,
      reason = "lucky_coin",
      pattern = ".|.|heart,club,diamond",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Spade then
      room:damage { from = nil, to = to, damage = 3, card = effect.card, skillName = self.name,
      damageType =  fk.ThunderDamage, }
    elseif result.suit == Card.Club then
      local targets = table.filter(room:getOtherPlayers(to), function (p) return not p:isNude() end)
      if #targets > 0 then
        local tos = room:askToChoosePlayers(to, {
          targets = targets, min_num = 1, max_num = 1, skill_name = self.name, cancelable = true,
          prompt = "#lucky_coin-choose",
        })
        if #tos > 0 then
          room:askToDiscard(tos[1], {
            min_num = 3, max_num = 3, skill_name = self.name, cancelable = false , include_equip = true,
          })
        end
      end
    elseif result.suit == Card.Heart and to:isWounded() then
      room:recover({ who = to, num = 2, skillName = self.name, recoverBy = to, card = effect.card })
    elseif result.suit == Card.Diamond then
      to:drawCards(3, self.name)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse,
    }
  end,
})

Fk:loadTranslationTable{
  ["lucky_coin_skill"] = "幸运硬币",
  ["#lucky_coin_skill"] = "置入你的判定区，下回合判定，除了♠都是好运！",
  ["#lucky_coin-choose"] = "幸运硬币：令一名其他角色弃置三张牌",
}
return skill
